using ServiceStack.Logging;
using System;
namespace ServiceStack.Support
{
	public abstract class AdapterBase
	{
		protected abstract ILog Log
		{
			get;
		}
		protected T Execute<T>(Func<T> action)
		{
			DateTime utcNow = DateTime.UtcNow;
			this.Log.DebugFormat("Executing action '{0}'", new object[]
			{
				action.Method.Name
			});
			T result;
			try
			{
				T t = action();
				TimeSpan timeSpan = DateTime.UtcNow - utcNow;
				this.Log.DebugFormat("Action '{0}' executed. Took {1} ms.", new object[]
				{
					action.Method.Name,
					timeSpan.TotalMilliseconds
				});
				result = t;
			}
			catch (Exception ex)
			{
				this.Log.ErrorFormat("There was an error executing Action '{0}'. Message: {1}", new object[]
				{
					action.Method.Name,
					ex.Message
				});
				throw;
			}
			return result;
		}
		protected void Execute(Action action)
		{
			DateTime utcNow = DateTime.UtcNow;
			this.Log.DebugFormat("Executing action '{0}'", new object[]
			{
				action.Method.Name
			});
			try
			{
				action();
				TimeSpan timeSpan = DateTime.UtcNow - utcNow;
				this.Log.DebugFormat("Action '{0}' executed. Took {1} ms.", new object[]
				{
					action.Method.Name,
					timeSpan.TotalMilliseconds
				});
			}
			catch (Exception ex)
			{
				this.Log.ErrorFormat("There was an error executing Action '{0}'. Message: {1}", new object[]
				{
					action.Method.Name,
					ex.Message
				});
				throw;
			}
		}
	}
}
